<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    <link rel="stylesheet" href="{{ url_for('static',filename='css/login/register.css') }}">
    <link rel="stylesheet" href="{{ url_for('static',filename='css/login/icon/iconfont.css') }}">
    <link rel="stylesheet" href="{{ url_for('static',filename='css/login/icon/iconfont2.css') }}">
    <link rel="stylesheet" href="{{ url_for('static',filename='css/login/xuehao/iconfont.css') }}">
    <link rel="stylesheet" href="{{ url_for('static',filename='css/login/phone/iconfont.css') }}">
    <link rel="stylesheet" href="{{ url_for('static',filename='css/login/email/iconfont.css') }}">
    <script type="text/javascript" src="{{ url_for('static',filename='js/jquery-3.6.0.min.js') }}"></script>
    <!-- layui样式文件 -->
    <link rel="stylesheet" href="//cdn.bootcdn.net/ajax/libs/layui/2.5.7/css/layui.min.css">
    <!-- layui脚本文件 -->
    <script src="//cdn.bootcdn.net/ajax/libs/layui/2.5.7/layui.min.js"></script>
</head>
<body>
<div class="main-content">
    <div class="formDiv">
        <h2 class="text-center" style="font-weight: bold;font-size: 24px">网上书店注册</h2>
        {#注册表单#}
        <form id="loginForm" method="post" action="{{ url_for('auth.register2') }}">
            <div class="dataform">
                <div class="input-warp gap">
                    <span class="input-icon iconfont icon-iconfontyonghuming"></span>
                    <input id="userName" name="userid" type="text" class="inputs" placeholder="学号" maxlength="64">
                </div>
                <div class="input-warp gap">
                    <span class="input-icon iconfont icon-yonghu1"></span>
                    <input id="Name" name="username" type="text" class="inputs" placeholder="姓名" maxlength="64">
                </div>
                <div class="input-warp gap">
                    <span class="input-icon iconfont icon-shoujihaoma"></span>
                    <input id="phone" name="phone" type="text" class="inputs" placeholder="手机号码" maxlength="64">
                </div>
                <div class="input-warp gap">
                    <span class="input-icon iconfont icon-youxiang"></span>
                    <input id="email" name="email" type="text" class="inputs" placeholder="邮箱地址" maxlength="64">
                </div>
                <div class="input-warp gap">
                    <span class="input-icon iconfont icon-mima"></span>
                    <input class="inputs" type="password" name="password1" placeholder="至少6位字母或数字" id="pwd" maxlength="20">
                </div>
                <div class="input-warp gap">
                    <span class="input-icon iconfont icon-mima"></span>
                    <input class="inputs" type="password" name="password2" placeholder="至少6位字母或数字" id="pwd2" maxlength="20">
                </div>
                <div class="btn-warp gap">
                    <div class="text-center">
                        <input type="hidden" value="jsform" id="_app"/>
                        <button type="submit" id="btnLogin" class="btn btn-block lgbtn blue">注册</button>
                    </div>
                </div>
                <div class="gap">
                    <div><span style="font-size: 14px">已有账号，</span><a style="font-size: 14px;color: rgb(100,158,253)" href="{{ url_for('hello') }}">登录</a></div>
                </div>
            </div>
        </form>
    </div>
</div>
<script>
    layui.use('layer', function(){
        var layer = layui.layer;
        {#表单提交进行注册#}
        $("#loginForm").submit(function (event) {
            event.preventDefault();
            var formData = $(this).serialize();
            console.log(formData);
            {#ajax请求参数是表单内容#}
            $.ajax({
                url:"/auth/register2",
                type:"post",
                data:formData,
                success:function (res){
                    if(res.state==200){     {#注册成功跳转到登录页面#}
                        layer.open({
                            title: '提示'
                            ,content: '注册成功！',
                            icon:1,
                            yes: function(layero, index){
                                console.log(layero, index);
                                window.location.href="{{ url_for('hello') }}"
                            }
                        });
                    }else {     {#失败跳转到注册页面#}
                        layer.open({
                            title: '提示'
                            ,content: res.msg,
                            icon:5,
                            yes: function(layero, index){
                                console.log(layero, index);
                                window.location.href="{{ url_for('auth.register1') }}"
                            }
                        });
                    }
                }
            });
        });
    });
</script>
</body>
</html>